﻿using System;
using System.Net;
using Nutshell.Distributing;
using Nutshell.Log;
using Nutshell.Messaging.Models;
using Nutshell.NetMQ;

namespace Nutshell.DLS.TestUI
{
        internal class Program
        {
                private static void Main(string[] args)
                {
                        NLoger.Separate();

                        var endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 10000);
                        var sender = new NetMQSender("日志发送者", endPoint);

                        var sendSite = new SendSite<LogMessageModel>("日志发送站点", sender);

                        sendSite.Start();

                        int count = 1;
                        var level = LogLevel.信息;

                        for (;;)
                        {
                                string input = Console.ReadLine();

                                if (input.IsNullOrEmpty())
                                {
                                        continue;
                                }

                                if (input == "exit")
                                {
                                        sendSite.Stop();
                                        break;
                                }

                                var segments = input.Split(new []{' '}, StringSplitOptions.RemoveEmptyEntries);

                                foreach (var s in segments)
                                {
                                        if (s.StartsWith(@"/d", StringComparison.CurrentCultureIgnoreCase))
                                        {
                                                level = LogLevel.调试;
                                        }

                                        if (s.StartsWith(@"/i", StringComparison.CurrentCultureIgnoreCase))
                                        {
                                                level = LogLevel.信息;
                                        }

                                        if (s.StartsWith(@"/w", StringComparison.CurrentCultureIgnoreCase))
                                        {
                                                level = LogLevel.警告;
                                        }

                                        if (s.StartsWith(@"/e", StringComparison.CurrentCultureIgnoreCase))
                                        {
                                                level = LogLevel.错误;
                                        }

                                        if (s.StartsWith(@"/c:", StringComparison.CurrentCultureIgnoreCase))
                                        {
                                                var c = s.Substring(3);
                                                 count = int.Parse(c);
                                        }
                                }

                                for (int i = 0; i < count; i++)
                                {
                                        var model = new LogMessageModel(segments[0], level);

                                        sendSite.Send(model);
                                }
                                
                        }
                }
        }
}
